package com.kylin.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kylin.R;
import com.kylin.eduservice.entity.EduCourse;
import com.kylin.eduservice.entity.EduTeacher;
import com.kylin.eduservice.service.EduCourseService;
import com.kylin.eduservice.service.EduTeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
//@CrossOrigin
public class IndexFrontController {

    @Autowired
    EduCourseService courseService;

    @Autowired
    EduTeacherService teacherService;

    //查询前8条热门课程，查询前4条名师
    @GetMapping("/index")
    @ApiOperation("查询前8条热门课程，查询前4条名师")
    public R index(){
        //查询前8条热门课程
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id").last("limit 8");
        List<EduCourse> eduCourseList = courseService.list(courseQueryWrapper);

        //查询前4条名师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id").last("limit 4");
        List<EduTeacher> eduTeacherList = teacherService.list(teacherQueryWrapper);

        return R.ok().data("eduList",eduCourseList).data("teacherList",eduTeacherList);
    }
}
